/*
 * 用来发送WebSocket消息
 */

/**
 * 普通消息类型
 * @type {string}
 */

function sendMessageToServer(messageText = '') {
    if (messageText.length <= 0) {
        return;
    }
    let data = {
        "tittle": 'MESSAGE',
        "message": messageText
    };
    operateToWebSocket(data);
}

function sendPlayChessToServer(playChess = {x: 0, y: 0}) {
    let content = {
        "tittle": 'PLAY_CHESS',
        "x": playChess.x,
        "y": playChess.y
    }
    operateToWebSocket(content);
}

function sendSystemToServer(roomCode = null, code, operate) {
    if (roomCode == null) {
        roomCode = ZhhSessionStorage_getItem('roomCode');
    }
    let content = {
        "tittle": "SYSTEM",
        "roomCode": roomCode,
        "code": code,
        "operate": operate
    };
    operateToWebSocket(content);
}

function operateToWebSocket(operate) {
    if (operate == null) {
        return;
    }
    let ws = window.socket;
    if (!ws) {
        return;
    }
    if (ws) {
        ws.send(JSON.stringify(operate));
    }
}


